<?php

      // header("Content-Type: application/json");
       
        
       
       $beginut=$_GET['startut'];
       $endut=$_GET['endut'];
        
       $fd=  fopen("archivos/datosut.txt", "w");
        //Se almacena la conexion en la variable $con
        
        $con=mysqli_connect("192.168.1.10","srojas","anemona") or die("Failed to connect with database!!!!");
        mysqli_select_db( $con,"hermes2"); 
        
       // $option="<script>document.write(option)</script>";
        
        // The Chart table contains two fields: publicacion_year and publicaciones
        //$sth = mysql_query("SELECT publicacion_year, count(*) as publicaciones  FROM papers_vs_citas GROUP BY publicacion_year");
        //}else {
        
        $sth = mysqli_query($con,"select publicacion_year as anio,count(*) as citas from citantes_isiwos group by publicacion_year"
                . " HAVING publicacion_year>=$beginut and publicacion_year<=$endut");
        
        
        //}
        mysqli_close($con);

        
       
        $rows = array();
        $table = array();
        $table['cols'] = array(

        // Labels for your chart, these represent the column titles
        // Note that one column is in "string" format and another one is in "number" format as pie chart only required "numbers" for calculating percentage and string will be used for column title
        array('label' => 'anio', 'type' => 'string'),
        array('label' => 'Citas', 'type' => 'number')

        );
        
        fwrite($fd, "Anio_publicacion   num_citas"."\r\n");
        while($r = mysqli_fetch_assoc($sth)) {
            fwrite($fd,"\t".$r['anio']."\t");
            fwrite($fd, $r['citas']."\r\n");
            
        $temp = array();
        // the following line will be used to slice the Pie chart
        $temp[] = array('v' => (string) utf8_encode($r['anio'])); 

        // Values of each slice
        $temp[] = array('v' => (int) $r['citas']); 
        $rows[] = array('c' => $temp);
        }

        $table['rows'] = $rows;
        
       
      /*  while($r = mysqli_fetch_assoc($sth)){
            foreach($r as $col_value){
                fwrite($fd, $col_value);
            }
        }*/
        fclose($fd);
        /*foreach($sth as $r) {

             $temp = array();

            // The following line will be used to slice the Pie chart

             $temp[] = array('v' => (int) $r['publicacion_year']); 

            // Values of the each slice

            $temp[] = array('v' => (int) $r['publicaciones']); 
            $rows[] = array('c' => $temp);
         }

        $table['rows'] = $rows;
       */
        echo json_encode($table)
        //$jsonTable = json_encode($table);
        
        //echo ''.json_encode($jsonTable).'';
        //echo $jsonTable;
        //print_r($jsonTable)
        
        
        //$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

        //
        //echo json_encode($arr);
        
        
        ?>
